package com.tshopping.controller;

import com.tshopping.service.StoreCollectionService;
import com.tshopping.util.ResponseData;
import com.tshopping.util.TimeProvider;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.ParseException;

/**
 * @name: StoreCollectionController
 * @description: 店铺收藏页面控制器
 * @author: Jackeys
 * @date: 2021-01-29 12:02
 */
@RestController
@RequestMapping("/StoreCollectionController")
@CrossOrigin
public class StoreCollectionController {

    @Autowired
    private StoreCollectionService storeCollectionService;

    @PostMapping(value = "/addStoreCollection")
    /**
     * @description 用户添加店铺收藏
     * @Param: user
     * @Param: store
     * @return ResponseData
     * @author Jackeys
     * @date 2021-01-29 12:29
     */
    public ResponseData addStoreCollection(int user, int store) throws ParseException {
        return storeCollectionService.addStoreCollection(user,store, TimeProvider.getTime());
    }

    @PostMapping(value = "/deleteStoreCollectionById")
    /**
     * @description 用户删除店铺收藏
     * @Param: id
     * @return ResponseData
     * @author Jackeys
     * @date 2021-01-29 12:30
     */
    public ResponseData deleteStoreCollectionById(int id){
        return storeCollectionService.deleteStoreCollectionById(id);
    }

    @PostMapping(value = "/getStoreCollectionList")
    /**
     * @description 返回用户收藏夹
     * @Param: user
     * @Param: currentPage
     * @return ResponseData
     * @author Jackeys
     * @date 2021-01-29 12:32
     */
    public ResponseData getStoreCollectionList(int user,int currentPage){
        return storeCollectionService.selectStoreCollectionList(user,currentPage);
    }

    @PostMapping(value = "/isStoreCollected")
    /**
     * @description 判断用户是否收藏店铺
     * @Param: goods
     * @Param: user
     * @return ResponseData
     * @author Jackeys
     * @date 2021-01-29 12:34
     */
    public ResponseData isStoreCollected(int store, int user){
        return storeCollectionService.selectCount(store,user);
    }

    @PostMapping(value="/deleteStoreCollection")
    /**
     * @description 处理用户取消收藏店铺
     * @Param: user
     * @Param: store
     * @return ResponseData
     * @author Jackeys
     * @date 2021-01-29 16:40
     */
    public ResponseData deleteStoreCollection(int user,int store){
        return storeCollectionService.deleteStoreCollectionByUserAndStore(user,store);
    }
}
